<template>
	<view class="u-page">
			<u-list
				@scrolltolower="scrolltolower"
			>	
				<u-list-item v-for="(item,index) in shopList"
						:key="index"
						height="120"
					>
					<shopitem :shopItem="item"> </shopitem>
				</u-list-item>
				<u-loadmore line fontSize="28rpx" :status="status" v-show="status!='loadmore'" />
			</u-list>
			
		</view>
</template>

<script>
	import shopitem from '../computed/shopitem.vue'
	export default {
		components:{shopitem},
		data() {
			return {
				shopList: [],
				status:'loadmore',
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png',
				queryObj:{
					query: '',
				    // 商品分类Id
				    cid: '',
				    // 页码值
				    pagenum: 1,
				    // 每页显示多少条数据
				    pagesize: 10
				},
				totle:0
			}
		},
		onLoad(options) {
			this.queryObj.cid=options.cat_id||''
			this.queryObj.query=options.query||''
			this.loadmore()
		},
		methods: {
			scrolltolower() {
				if(this.status=='loading'){
					return
				}
				if(this.shopList.length+this.queryObj.pagesize>this.totle){
					return this.status='nomore'
				}
				this.loadmore()
			},
			async loadmore() {
				let {data}=await uni.$http.get('/api/public/v1/goods/search', this.queryObj)
				this.totle=data.message.total
				this.status='loading'
				this.shopList=[...this.shopList,...data.message.goods]
				console.log(this.shopList.length,this.totle)
				this.queryObj.pagenum+=1
				this.status='loadmore'
			}
		},
	}
</script>

<style>
	.leftimg{
		width: 200rpx;
		height: 200rpx;
		max-heihgt:200rpx;
	}
	.shopitem{height: auto;}
	.rtit{
		font-size: 28rpx;
		white-space: pre-wrap;
		width: 100%;
	}
	.rprice{
		color:rgb(195,21,20);
		font-size: 35rpx;
	}
	.hahah{width:80%;}
	uni-scroll-view{
		flex-shrink:none;
	}
	/* 加载更多 */
	.u-loadmore__content__text{
		line-height:inherit !important;
	}
</style>
